﻿program Game;

//{$APPTYPE CONSOLE}
{$ifdef fpc} {$mode delphi} {$endif}

uses
  SysUtils,
  Classes,

  zglHeader,
  zglChipmunk,

  Orion,

  GameAbstract,
  GameAbstract_OrionScript,
  GameAbstract_OrionAdapter,

  GameAbstract_Types,
  GameAbstract_Utils,
  GameAbstract_Format,
  GameAbstract_Events,
  GameAbstract_Map,
  GameAbstract_Sprite;


procedure LoadData;
begin
   GameOptions.RealPath := GameOptions.RealPath + '../';
   GameOptions.DataPath := GameOptions.RealPath + '/data/';

   GameManager := TGameFormat.Create;
   GameManager.SetAdapter( JSON_Adapter );
   GameManager.LoadFromFile('format/test.json');
end;

procedure MyInit( Event: TGameEvent; Param: Integer; dt: Double );
  var
  Map: TGameIzoTargetMap;
  Tex: TGameTexture;
  i, j: integer;
begin
  Map := TGameIzoTargetMap.Create;
  Map.SizeWidth  := 64;
  Map.SizeHeight := 33;
  Map.Border.W := 0;
  Map.Border.H := 0;
  Map.CountX := 4;
  Map.CountY := 4;

  Map.X := -32;
  Map.Y := -16;

  Tex := TGameTexture.Create(64,32);
  Tex.LoadFromFile( 'data/tileset.png' );
  Map.SetIzoTexture(Tex);

  for i := 0 to 3 do
  for j := 0 to 3 do
    with Map.Map[ i, j ] do
    begin
      Index := 4;
      IsIzometric := true;
    end;


  with TGameLayer.Create do
  begin
     Map.Visible := true;
     Link( Map );
  end;
end;

begin
  TOrionEngine.ModuleAdd( @Orion_WrapImport );
  OrionScript := TOrionEngine.Create(true);
  OrionScript.setErrorHandle(@ga_OrionErrorHandler);

  GameEngine := TGameEngine.Create('ZenGl.dll');
  GameEngine.OnInit.Add(MyInit);

  if FileExists( 'appb.ori') then
     OrionScript.Include( 'appb.ori', True )
  else
     OrionScript.Include( 'app.ori' );
end.
